//
//  FilterOptionalModel.swift
//  Automobile
//
//  Created by erkebulan elzhan on 8/3/20.
//  Copyright © 2020 erkebulan elzhan. All rights reserved.


import Foundation


class FilterOptionalModel {
    
    var filterOptional: Filter.FilterOptional!
    var pickerData: [ModalView.ModalType: [Double]] = [:]
    
    
    @Range var powerText: String = ""
    @Range var yearText: String = ""
    @Range var probegText: String = ""
    @Range var volumeText: String = ""
    @Range var expenditureText: String = ""
    @Range var priceText: String = ""
    
    init (filterOptional: Filter.FilterOptional) {
        self.filterOptional = filterOptional
        
        powerText = "\(filterOptional.powerFrom ?? 0)-\(filterOptional.powerTo ?? 0)"
        yearText = "\(filterOptional.yearFrom ?? 0)-\(filterOptional.yearTo ?? 0)"
        probegText = "\(filterOptional.probegFrom ?? 0)-\(filterOptional.probegTo ?? 0)"
        volumeText = "\(filterOptional.volumeFrom ?? 0)-\(filterOptional.volumeTo ?? 0)"
        expenditureText = "\(filterOptional.expenditureFrom ?? 0)-\(filterOptional.expenditureTo ?? 0)"
        priceText = "\(filterOptional.priceFrom ?? 0)-\(filterOptional.priceTo ?? 0)"
        
        
        let modalViewModel = ModalViewModel()
        pickerData = modalViewModel.pickerData
    }
    
    func updatePower (powerOt: Int?, powerDo: Int?) {
        self.filterOptional.powerFrom = powerOt
        self.filterOptional.powerTo = powerDo
        powerText = "\(filterOptional.powerFrom ?? 0)-\(filterOptional.powerTo ?? 0)"
    }
    
    func updatePrice (from: Int?, to: Int?) {
        self.filterOptional.priceFrom = from
        self.filterOptional.priceTo = to
        priceText = "\(filterOptional.priceFrom ?? 0)-\(filterOptional.priceTo ?? 0)"
    }
    
    func updateYear (yearOt: Int?, yearDo: Int?) {
        self.filterOptional.yearFrom = yearOt
        self.filterOptional.yearTo = yearDo
        yearText = "\(filterOptional.yearFrom ?? 0)-\(filterOptional.yearTo ?? 0)"
    }
    
    func updateProbeg (from: Int?, to: Int?) {
        self.filterOptional.probegFrom = from
        self.filterOptional.probegTo = to
        probegText = "\(filterOptional.probegFrom ?? 0)-\(filterOptional.probegTo ?? 0)"
    }
    
    func updateVolume (from: Double?, to: Double?) {
        self.filterOptional.volumeFrom = from
        self.filterOptional.volumeTo = to
        volumeText = "\(filterOptional.volumeFrom ?? 0)-\(filterOptional.volumeTo ?? 0)"
    }
    
    func updateExpenditure (from: Int?, to: Int?) {
        self.filterOptional.expenditureFrom = from
        self.filterOptional.expenditureTo = to
        expenditureText = "\(filterOptional.expenditureFrom ?? 0)-\(filterOptional.expenditureTo ?? 0)"
    }
    
    func updatePrivod (privod: [ModalView.ModalData]) {
        self.filterOptional.privods = privod
    }
    
    func updateColor (color: [ModalView.ModalData]) {
        self.filterOptional.colors = color
    }
    
    func updateKorobka (korobka: [ModalView.ModalData]) {
        self.filterOptional.korobka = korobka
    }
    
    func updateKuzov (kuzov: [ModalView.ModalData]) {
        self.filterOptional.kuzov = kuzov
    }
    
    func updateDvigatel (dvigatel: [ModalView.ModalData]) {
        self.filterOptional.dvigatel = dvigatel
    }
    
    func updateRule (rule: [ModalView.ModalData]) {
        self.filterOptional.rule = rule
    }
}
